using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.DesignerSupport;

namespace XMTAEditor
{
	internal static class BindUtil
	{
		public static string ToText(object o)
		{
			if (o == null) return string.Empty;
			return o.ToString();
		}

		public static string ToText(objecttype o)
		{
			if (o == null) return string.Empty;
			return o.ToString();
		}

		public static string ToText(typedeftype o)
		{
			if (o == null) return string.Empty;
			return o.ToString();
		}

		public static System.Windows.Forms.CheckState ToCheck(bool? o)
		{
			if (!o.HasValue) return System.Windows.Forms.CheckState.Indeterminate;
			return o.Value ? System.Windows.Forms.CheckState.Checked : System.Windows.Forms.CheckState.Unchecked;
		}

		public static bool? FromCheck(System.Windows.Forms.CheckState s)
		{
			if (s == System.Windows.Forms.CheckState.Indeterminate)
				return null;
			else if (s == System.Windows.Forms.CheckState.Checked)
				return true;
			return false;
		}

		public static string ToVar(string o)
		{
			if (string.IsNullOrEmpty(o)) return null;
			return o;
		}

		public static objecttype ToObject(string s, Type type)
		{
			if (string.IsNullOrEmpty(s))
				return null;
			objecttype ot = new objecttype(type);
			ot.Value = s;
			return ot;
		}
	}
}
